﻿
CREATE PROCEDURE [dbo].[CreazaArhivaExBug]
	@An smallint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @strContAn varchar(40)
	DECLARE @Comanda varchar(3000)
	DECLARE @existTableCont bit
	
	SET @strContAn = 'Ordonantari' + cast(@An AS varchar(4)) 
	SET @existTableCont = 0
	IF EXISTS(SELECT * FROM sys.tables WHERE NAME LIKE @strContAn)
		SET @existTableCont = 1
	
	--verifica existenta tabeleli arhiva
	SET @Comanda = 'SELECT * INTO [' + @strContAn + '] FROM [Ordonantari]'
	
	IF @existTableCont = 0
		EXEC(@Comanda)
		

		

END